package com.rattsoftware.server.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import com.rattsoftware.server.admin.model.Faculty;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;
import com.rattsoftware.server.dao.FacultyDAO;

/**
 * Provides a hibernate implementation
 * of the <code>FacultyDAO</code> data access <code> interface.</code>
 */
@Repository("facultyDAO")
public class HibernateFacultyDAO extends BaseDAOImpl<Faculty> implements FacultyDAO {

	@Override
	public void deleteFaculty(Faculty faculty) {
		remove(faculty);
	}

	@Override
	public List<Faculty> getFaculties() {
		Search s = new Search();
		s.addSort("name", false);
		return search(s);
	}

	@Override
	public Faculty getFaculty(Integer id) {
		return super.find(id);
	}

	@Override
	public PagingLoadResult<Faculty> getFacultyList(
			PagingLoadConfig pagingLoadConfig) {
		Search departmentSearch = getSearchFromLoadConfig(pagingLoadConfig, "id");
		SearchResult<Faculty> result = searchAndCount(departmentSearch);
		return getPagingLoadResult(pagingLoadConfig, result);
	}

	@Override
	public void saveFaculty(Faculty faculty) {
		save(faculty);
	}
}